package com.wjy.common.controller;

import com.alibaba.druid.stat.DruidStatManagerFacade;
import com.wjy.common.result.ResultBuilder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api(tags = "阿里巴巴数据源控制")
@Log4j2
@RestController
public class DruidController {

    @ApiOperation(value = "获取阿里巴巴数据源监控数据")
    @RequestMapping(value = "/getDruid", method = RequestMethod.GET)
    public ResultBuilder getDruid() {
        try {
            List<Map<String, Object>> list = DruidStatManagerFacade.getInstance().getDataSourceStatDataList();
            return ResultBuilder.success(list);
        } catch (Exception e) {
            log.error(e);
            e.printStackTrace();
            return ResultBuilder.error(e);
        }
    }

}
